//节流函数(返回一个新函数。立即执行，指定时间内不会再次执行)
module.exports = function(func, delay){
    let timer, last;
    return function () {
        const _this = this;
        const _args = arguments;
        const now = +new Date();
        if (last && now < last + delay) {
            clearTimeout(timer);
            timer = setTimeout(() => {
                last = now;
                func.apply(_this, _args);
            }, delay);
        } else {
            last = now;
            func.apply(this, _args);
        }
    }
}